import {
    createWebHistory,
    createRouter
} from 'vue-router'
import Home from '../pages/common/home.vue'
const routes = [
    {
        path: '/',
        redirect: '/ghost'
    },
    {
        path: '/',
        name: 'home',
        component: Home,
        children: [
            {
                path: "/404",
                name: "index",
                meta: {
                    title: '404'
                },
                component: () => import('@/pages/common/404.vue')
            },
            {
                path: "/index",
                name: "index",
                meta: {
                    title: '首页'
                },
                component: () => import('../pages/index.vue')
            },
            {
                path: "/index_v2",
                name: "index",
                meta: {
                    title: '签到'
                },
                component: () => import('../pages/index_v2.vue')
            },
            {
                path: "/manager",
                name: "manager",
                meta: {
                    title: '地府人员管理'
                },
                component: () => import('../pages/manager.vue')
            },
            {
                path: "/ghost",
                name: "ghost",
                meta: {
                    title: '厉鬼管理'
                },
                component: () => import('@/pages/ghost/index.vue')
            },
            {
                path: "/user_name",
                name: "user_name",
                meta: {
                    title: '名单管理'
                },
                component: () => import('@/pages/user_name/index.vue')
            },
            {
                path: "/table",
                name: "table",
                meta: {
                    title: 'demo'
                },
                component: () => import('@/views/demo/index.vue')
            }
        ]
    }, {
        path: "/login",
        name: "login",
        meta: {
            title: '登录'
        },
        component: () => import('@/pages/common/login.vue')
    }]
const routerHistory = createWebHistory();
const router = createRouter({
    history: routerHistory,
    routes
})
router.beforeEach((to, from, next) => {
    const role = localStorage.getItem('token');
    if (!role && to.path !== '/login') {
        next('/login')
    } else {
        next();
    }
})
export default router;